package com.letou.ls.uitl;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.letou.ls.ui.FifFiveActivity;
import com.letou.ls.ui.FifFiveHarActivity;
import com.letou.ls.ui.HappyMajiangActivity;
import com.letou.ls.ui.HappyTenActivity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

public class MyUtil {
    
    public static Intent getIntentById(Context context, String code) {
        Log.e("lb", "getIntentById:" + code + "--->"
                + PreferencesUtils.getInt(context, AppShowSettingType.SCREEN_DIRECTION_TYPE, 1));
        if (TextUtils.isEmpty(code)) {
            return null;
        }
        Intent intent = null;
        if (Constant.LOTTERY_CODE_01.equals(code)) {
            intent = new Intent(context, HappyTenActivity.class);
        } else if (Constant.LOTTERY_CODE_02.equals(code)) {
        	
        } else if (Constant.LOTTERY_CODE_03.equals(code)) {
            
            intent = new Intent(context, HappyMajiangActivity.class);
        } else if (Constant.LOTTERY_CODE_04.equals(code)) {
            int screen =
                    PreferencesUtils.getInt(context, AppShowSettingType.SCREEN_DIRECTION_TYPE, 1);
            if (screen == 0) {// 竖
                intent = new Intent(context, FifFiveActivity.class);
            } else {
                intent = new Intent(context, FifFiveHarActivity.class);
            }
        }
        return intent;
    }



    public static boolean isScreenSwith(String code) {
        if (TextUtils.isEmpty(code)) {
            return false;
        }
        boolean isScreenSwith = true;
        if (Constant.LOTTERY_CODE_01.equals(code)) {
            isScreenSwith = Constant.isScreenSwith_01;
        } else if (Constant.LOTTERY_CODE_02.equals(code)) {
            isScreenSwith = Constant.isScreenSwith_02;
        } else if (Constant.LOTTERY_CODE_03.equals(code)) {
            isScreenSwith = Constant.isScreenSwith_03;
        } else if (Constant.LOTTERY_CODE_04.equals(code)) {
            isScreenSwith = Constant.isScreenSwith_04;
        }
        return isScreenSwith;
    }
    
    public static String changEncoding(String str) {
        
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        String result = null;
        try {
            result = URLEncoder.encode(str, "gb2312");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } // 匹配整个字符串
        return result;
    }
    
    public static String getErrByCode(String code) {
        
        if ("401".equals(code)) {
            return "用户验证失败，请重新登陆。";
        } else if ("402".equals(code)) {
            return "用户期限已到期，请联系客服。";
        } else if ("403".equals(code)) {
            return "您的帐号已在其他终端登录，请联系客服。";
        } else if ("500".equals(code)) {
            return "服务器异常，请联系客服。";
        }
        
        // int number = Integer.valueOf(code);
        // if (number > 500 && number < 600) {
        //
        // }
        return "";
    }
}
